<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>扫码结果确认</title>
		<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="format-detection" content="telephone=no, address=no, email=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="css/mui.min.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
		<style>
			.mui-content {
				width: 93.6%;
				position: absolute;
				top: 45%;
				left: 50%;
				transform: translate(-50%, -50%);
				-webkit-transform: translate(-50%, -50%);
				-moz-transform: translate(-50%, -50%);
			}
			
			p.scanStatus {
				font-size: 48px;
				margin-top: 0.5rem;
			}
			
			.error p.scanStatus {
				font-size: 32px;
			}
			
			.content {
				text-align: left;
				margin-top: 1rem;
				background: #fff;
				padding: 0.15rem;
			}
			
			.content p {
				font-size: 30px;
			}
			
			.mui-select:before {
				top: 12px;
			}
			
			@media screen and (min-width:321px) and (max-width:375px) {
				p.scanStatus {
					font-size: 24px;
				}
				.error p.scanStatus {
					font-size: 20px;
				}
				.content p {
					font-size: 16px;
				}
			}
			
			@media screen and (min-width:376px) and (max-width:414px) {
				p.scanStatus {
					font-size: 28px;
				}
				.error p.scanStatus {
					font-size: 22px;
				}
				.content p {
					font-size: 18px;
				}
			}
			
			@media screen and (min-width:415px) and (max-width:639px) {
				p.scanStatus {
					font-size: 32px;
				}
				.error p.scanStatus {
					font-size: 24px;
				}
				.content p {
					font-size: 20px;
				}
			}
			
			@media screen and (min-width:640px) and (max-width:719px) {
				p.scanStatus {
					font-size: 40px;
				}
				.error p.scanStatus {
					font-size: 26px;
				}
				.content p {
					font-size: 26px;
				}
			}
			
			@media screen and (min-width:720px) and (max-width:749px) {
				p.scanStatus {
					font-size: 44px;
				}
				.error p.scanStatus {
					font-size: 28px;
				}
				.content p {
					font-size: 28px;
				}
			}
			
			@media screen and (min-width:750px) and (max-width:799px) {
				p.scanStatus {
					font-size: 48px;
				}
				.error p.scanStatus {
					font-size: 32px;
				}
				.content p {
					font-size: 30px;
				}
			}
			.loading{
				position:absolute;top:40%;z-index:999;left:40%;
			}
		</style>
	</head>

	<body>
		<div class="mui-backdrop none">
			<div class="loading mui-hidden">
				<div class="mui-pull-loading mui-icon mui-spinner"></div>
			</div>
		</div>
		
		<header class="mui-bar mui-bar-nav mui-header">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">扫码结果</h1>
		</header>

		<div class="mui-content text-center">
			<img src="" id="pimg" style="width:2.95rem" />
			<div class="pinfo">
				<div class="content ">
					<p>产品名称：<span id="pname"></span></p>
					<p>操作类型：<span id="pway"></span></p>
					<p>采集数量：<span id="pcount"></span></p>
					<p id='resouce'></p>
				</div>
				<div class="mui-select">
					<select id="selectedJXS" style=""></select>
				</div>
			</div>
		</div>

		<div class="mui-bar" style="bottom:0.26rem;background:transparent;border:none;">
			<button class="mui-btn" style="background:#f1c40f;border-color:#f1c40f" id="cancel">取消</button>
			<button class="mui-btn" style="background:#32b16c;border-color:#32b16c;margin-left:2%;" id="success">完成</button>
		</div>

		<script src="js/resize.js"></script>
		<script src="js/redirect.js"></script>
		<script src="js/mui.min.js"></script>
		<script src="js/ajaxFun.js"></script>
		<script src="js/dialog.js"></script>
		<script>
			var jxslistUro = baseUrl + 'outScan/getTraderList.do';
			var $ = mui,cur;
			var cobj = document.getElementById("cancel");
			var sobj = document.getElementById("success");
			var flag = 1,scancount=0;
			var totalCount=0;
			 
			function open() {
				var a=plus.webview.getWebviewById('main-inout');
				a.show();
				mui.fire(a,'flagParam',{
					flagParam:flag
				});
//				cur.close();
			}
			function plusReady() {
				cur=plus.webview.currentWebview();
				/*2017-3-15改版通过扫描那边传递的数据改为重新调用接口获取数据*/
				var pinfo = JSON.parse(localStorage.getItem('scanResult') || '[]');
				if(pinfo) {
					flag = pinfo.flag;
					var url = flag == 1 ? baseUrl+"outScan/get/traderout/by/outno.do" : flag == 2 ? baseUrl+'in/get/traderin/by/inno.do' : '';
					var data = flag == 1 ? {
						outNo: pinfo.outNo
					} : flag == 2 ? {
						inNo: pinfo.inNo
					} : '';
					if(url) {
						ajaxFun.postFun(url, data, '', function(d) {
							var info = d.data;
							if(info){
								totalCount= flag == 2 && info.totalcount;
								scancount=info.count;
							}
							document.getElementById("pimg").src = info.imgUrl ? routeUrl + info.imgUrl : '';
							document.getElementById("pname").innerHTML = info.productName? info.productName:'';
							document.getElementById("pway").innerHTML = flag == 1 ? "出库" : flag == 2 ? '入库' : '';
							document.getElementById("pcount").innerHTML = flag == 1 ? info.count + '箱' : flag == 2 ? info.count + ' / ' + info.totalcount + '箱' : '';
							//出库的情况下获取经销商列表
							if(flag == 1) {
								ajaxFun.postFun(jxslistUro, {
									productNo: info.productNo
								}, '', function(d) {
									var list = d.data,
										html = '<option value="">请选择经销商</option>';
									for(key in list) {
										html += '<option value="' + key + '">' + list[key] + '</option>';
									}
									document.getElementById("selectedJXS").innerHTML = html;
								});
							} else if(flag == 2) {
								document.getElementById("resouce").innerHTML = '来源：<span id="psource">' + info.sendTraderName + '</span>';
								document.querySelectorAll('.pinfo')[0].removeChild(document.querySelector('.mui-select'));
							}
						},'',function(){
								localStorage.clear();
								openWindow('./login.html','login');
						});
					} else {
						plus.nativeUI.alert('扫码信息不存在！');
						open();
						return false;
					}
				} else {
					plus.nativeUI.alert('扫码信息不存在！');
					open();
					return false;
				}
	 
				//回到出入库首页
				mui(document.body).on('tap','#cancel',function(){
					open();
				})

				mui(document.body).on('tap','#success',function(){
					if(pinfo) {
						/*如果是入库就判断是否入库数量正确，如果不正确就提示之后提交*/
						if(pinfo.flag == 2) {
							if(scancount!= totalCount) {
								var dialogObj = new DialogObj();
								dialogObj.showConfirm('提示', '入库数量不符合，确定要提交入库吗？', {
									yes: {
										'msg': '确定',
										'callback': function() {
											submitFun(pinfo);
										},
										'isexist': true,
									},
									no: {
										'msg': '取消',
										'callback': function() {
											document.getElementsByTagName('body')[0].removeChild(dialogObj.currentDialogObj);
										},
										'isexist': true,
									}
								});
							} else {
								submitFun(pinfo);
							}
						} else if(pinfo.flag == 1) {
							submitFun(pinfo);
						}

					} else {
						plus.nativeUI.alert('扫码信息不存在！');
						open();
					}
				})
				 
			}

			if(window.plus) {
				plusReady();
			} else {
				document.addEventListener("plusready", plusReady, false);
			}
			function submitFun(pinfo) {
				var loadingEle=document.querySelector('.loading');
				removeClass(document.querySelector('.mui-backdrop'),'none')
				removeClass(loadingEle,'mui-hidden') ;
			 
				//完成扫码处理事件
				var url = pinfo.flag == 1 ? baseUrl + 'outScan/completeTraderOut.do' : baseUrl + 'in/completeTraderIn.do';
				var data = pinfo.flag == 1 ? {
					'outNo': pinfo.outNo,
					'receivedTraderId': document.getElementById("selectedJXS").value
				} : {
					'count': pinfo.count,
					'outNo': pinfo.outNo,
					'inNo': pinfo.inNo,
					'productNo': pinfo.productNo
				};
				if(pinfo.flag == 1 && 　!data.receivedTraderId) {
					addClass(document.querySelector('.mui-backdrop'),'none')
					addClass(loadingEle,'mui-hidden') ;
					plus.nativeUI.alert('请选择经销商！');
					return false;
				}
				setTimeout(function(){
					ajaxFun.postFun(url, data, '', function(d) {
						addClass(document.querySelector('.mui-backdrop'),'none')
						addClass(loadingEle,'mui-hidden') ;
						open();
					},function(d){
						addClass(document.querySelector('.mui-backdrop'),'none')
						addClass(loadingEle,'mui-hidden') ;
						plus.nativeUI.alert(d.msg)
					},function(){
						localStorage.clear();
						openWindow('./login.html','login');
					})
				},500);
				
			}
		</script>

	</body>

</html>